package fr.sedoo.sos.domain;

import java.util.ArrayList;
import java.util.List;

public class Sensor extends IsLocalized
{
	private String urn;
	private String shortName;
	private String longName;
	
	private String featureOfInterest;
	
	/**
	 * Indicate that all localisation informations are given by the station
	 */
	
	private ObservationStation station;
	
	List<Phenomenon> phenomena = new ArrayList<Phenomenon>();
	
	public void addPhenomenon(Phenomenon phenomenon)
	{
		phenomena.add(phenomenon);
	}
	
	public List<Phenomenon> getPhenomena() {
		return phenomena;
	}

	public void setUrn(String urn) {
		this.urn = urn;
	}

	public ObservationStation getStation() {
		return station;
	}
	
	public String getOffering()
	{
		return getUrn();
	}

	public void setStation(ObservationStation station) {
		this.station = station;
	}
	
	public String getUrn() throws IllegalArgumentException
	{
		ObservationStation station = getStation();
		if (urn != null)
		{
			return urn;
		}
		else
		{
			try
			{
				return ("urn:"+station.getExperimentalSite().getObservatory().getProgram().getId()+":sensor:"+station.getExperimentalSite().getObservatory().getId()+":"+station.getExperimentalSite().getId()+"_"+station.getId()).toLowerCase()+":"+getId();
			}
			catch (NullPointerException e)
			{
				throw new IllegalArgumentException("Impossible de constituer l'URN");
			}
		}
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public String getLongName() {
		return longName;
	}

	public void setLongName(String longName) {
		this.longName = longName;
	}
	
	
	@Override
	public IsLocalized getContainer() 
	{
		return station;
	}

	public String getFeatureOfInterest() 
	{
		if (featureOfInterest != null)
		{
			return featureOfInterest;
		}
		else
		{
			return getStation().getFeatureOfInterest();
		}
	}
}
